

*this program does not use absolute paths
*it assumes that upon starting Stata, the user sets working directory 

*load in rawdata.dta which was created using importing data.do
use rawdata, clear
**Converting Wheat aid and production to thousands of tonnes
replace uswheat_aid=uswheat_aid/1000 	
replace uswheat_prod=uswheat_prod/1000

**Creating rainshock variable
egen countrynum = group(country)
order country countrynum
sort country 
by country:  egen avrain = mean(avg_annual_precip)
gen rainshock = avg_annual_precip/avrain

**Interaction of uswheat_prod with avg_fap
xtset countrynum year
gen inst1 = l.uswheat_prod*avg_fap

**Various measures of IMR
gen dlnimr = ln(imr)-ln(l.imr)
gen dimr = imr-l.imr 
sort country
by country: egen avimr = mean(imr)

**Creating natural log of US wheat aid variable
gen lnfaid = ln(1+uswheat_aid)

**Creating natural log of population variable
gen lnpop = ln(1+total_population)

**Creating UN voting records variable
bysort country: egen unvotes_avg=mean(unvotes) if year>=1981 & year<=2006
sum unvotes_avg if year==2000, detail
gen Align=.
replace Align=1 if unvotes_avg>.5189338 & missing(unvotes_avg)!=1
replace Align=0 if unvotes_avg<=.5189338
sum Align, detail
gen uswheat_aid_x_Align=uswheat_aid*Align

**Interaction of US production variables with avg_fap for placebo test
sort countrynum year  
gen cabbage = (l.USprod_Cabbages/1000)* avg_fap
gen carrots_turnips= (l.USprod_Carrots_turnips/1000)* avg_fap
gen cotton_lint= (l.USprod_Cotton_lint/1000)*avg_fap
gen grapefruit= (l.USprod_Grapefruit/1000)*avg_fap
gen grapes= (l.USprod_Grapes/1000)*avg_fap
gen lettuce= (l.USprod_Lettuce/1000)*avg_fap
gen onions_dry= (l.USprod_Onions_dry/1000)*avg_fap
gen oranges= (l.USprod_Oranges/1000)*avg_fap
gen peaches_nectarines= (l.USprod_Peaches_nectarines/1000)*avg_fap
gen watermelons= (l.USprod_Watermelons/1000)*avg_fap

save processed_data, replace
*this file will be used by creating tables.do
